package com.example.controller;

import com.example.common.enums.ResponseCodeEnum;
import com.example.common.utils.ApiResult;
import com.example.model.entity.SuppliesType;
import com.example.model.query.SuppliesQuery;
import com.example.model.query.SuppliesTypeQuery;
import com.example.model.vo.SuppliesTypeVo;
import com.example.service.SuppliesService;
import com.example.service.SuppliesTypeService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Value;

/**
 * SuppliesType Controller
 * 2020-08-27 18:59
 */
@Controller
@RestController
@RequestMapping("/suppliesType")
@CrossOrigin
@Api(value = "物资类型管理",tags={"物资类型管理接口"})
public class SuppliesTypeController {

	private static final Logger logger = LoggerFactory.getLogger(SuppliesTypeController.class);

	@Autowired
	private SuppliesTypeService suppliesTypeService;

	/**
	 * 分页查询列表
	 */
	@GetMapping("/page")
	public ApiResult<SuppliesTypeQuery> pageByQuery(SuppliesTypeQuery query) {
		try {
			return suppliesTypeService.pageUserVoByQuery(query);
		}   catch (Exception e) {
			e.printStackTrace();
			return new ApiResult<>(ResponseCodeEnum.MALL_SERVICE_PAGE_AD_FALSE);
		}
	}

	@PostMapping("/save")
	public ApiResult<Boolean> save(@RequestBody SuppliesTypeVo suppliesTypeVo) {
		try {
			return suppliesTypeService.saveAd(suppliesTypeVo);
		}  catch (Exception e) {
			e.printStackTrace();
			return new ApiResult<>(Boolean.FALSE, ResponseCodeEnum.MALL_SERVICE_SAVE_AD_FALSE);
		}
	}

	@GetMapping("/get/{id}")
	public ApiResult<SuppliesTypeVo> get(@PathVariable("id") String id){
		try {
			return suppliesTypeService.getInfo(id);
		}catch (Exception e){
			e.printStackTrace();
			return new ApiResult<>(ResponseCodeEnum.MALL_SERVICE_ORDER_GET_FALSE);
		}
	}

	@PostMapping("/modify")
	public ApiResult<Boolean> update(@RequestBody SuppliesTypeVo suppliesTypeVo) {
		try {
			return suppliesTypeService.update(suppliesTypeVo);
		}catch (Exception e){
			e.printStackTrace();
			return new ApiResult<>(ResponseCodeEnum.MALL_SERVICE_ORDER_UPDATE_FALSE);
		}
	}

	@GetMapping("/del/{id}")
	public ApiResult<Boolean> del(@PathVariable("id") String id){
		try {
			return suppliesTypeService.del(id);
		}catch (Exception e){
			e.printStackTrace();
			return new ApiResult<>(ResponseCodeEnum.MALL_SERVICE_ORDER_GET_FALSE);
		}
	}
	
}
